#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<ctemplate/template.h>
#include"oj_model.hpp"
namespace ns_view
{const std::string template_path="./template_html/";
using namespace ns_model;
class View
{
   public:
   View(){}
   ~View(){}
   public:
   void AllExpandHtml(const std::vector<ns_model::Question> &questions,std::string *html)
   {
       std::string src_html=template_path+"all_questions.html";
       ctemplate::TemplateDictionary root("all_question");
       for(const auto &q:questions)
       {
           ctemplate::TemplateDictionary *sub=root.AddSectionDictionary("question_list");
           sub->SetValue("num",q.num);
           sub->SetValue("title",q.title);
           sub->SetValue("star",q.star);

       }
       ctemplate::Template *tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
       tpl->Expand(html,&root);
   }
   void OneExpandHtml(const ns_model::Question &q,std::string *html)
   {
    std::string src_html=template_path+"one_question.html";
    ctemplate::TemplateDictionary root("one_question");
    root.SetValue("num",q.num);
    root.SetValue("title",q.title);
    root.SetValue("star",q.star);
    root.SetValue("desc",q.desc);
    root.SetValue("pre_code",q.header);
    ctemplate::Template *tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
    tpl->Expand(html,&root);

   }

};
}